package com.winning.devops.batch.writer.ch03.config;

import com.winning.devops.batch.writer.ch03.domain.Customer;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 普通文件ItemWriter 配置
 *
 * @author chensj
 * @date 2020-03-07 16:40
 */
@Configuration
public class FlatFileWriterDemoJobConfig {
    @Autowired
    private JobBuilderFactory jobBuilderFactory;
    @Autowired
    private StepBuilderFactory stepBuilderFactory;

    @Autowired
    @Qualifier("jdbcPagingItemDemoReader")
    private ItemReader<? extends Customer> jdbcPagingItemDemoReader;
    @Autowired
    @Qualifier("flatFileDemoWriter")
    private ItemWriter<? super Customer> flatFileDemoWriter;

    @Bean
    public Job flatFileWriterDemoJob() {
        return jobBuilderFactory.get("flatFileWriterDemoJob")
                .start(flatFileWriterDemoStep())
                .build();
    }

    @Bean
    public Step flatFileWriterDemoStep() {
        return stepBuilderFactory.get("flatFileWriterDemoStep")
                .<Customer, Customer>chunk(10)
                .reader(jdbcPagingItemDemoReader)
                .writer(flatFileDemoWriter)
                .build();
    }
}
